
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessObject;
using DataAccessLayer;

namespace BusinessLogic
{
    /// <summary>
    /// Define MatHangUtil class. This class user for BussinessLayer.

    /// </summary>
    public class MatHangUtil
    {
        /// <summary>
        /// Define function Insert for MatHang Object.
        /// </summary>
        /// <param name="t">object data need Insert.</param>
        /// <returns>
        ///    True: if insert successfull.
        ///    False: if insert error.
        ///</returns>
        public static int Insert(MatHang t, List<HinhAnhMatHang> lstImage)
        {
            BizObject.PurgeCacheItems("MatHang");

            return MatHangDao.Insert(t,lstImage);
        }
        /// <summary>
        /// Define function Update for MatHang Object.
        /// </summary>
        /// <param name="t">project data need updated.</param>
        /// <returns>
        ///    True: if update successful.
        ///    False: if update Error.
        ///</returns>
        public static int Update(MatHang t,List<HinhAnhMatHang> lstHinhAnh)
        {
            BizObject.PurgeCacheItems("MatHang");

            return MatHangDao.Update(t, lstHinhAnh);
        }
        /// <summary>
        /// Get All MatHang object from table MatHang.
        /// </summary>
        /// <returns>List MatHang object.</returns>
        public static List<MatHangResult> GetAll()
        {
            List<MatHangResult> obj = null;
            string key = "MatHang_GetAll";
            if (BizObject.Cache[key] != null)
            {
                obj = (List<MatHangResult>)BizObject.Cache[key];
            }
            else
            {
                obj = MatHangDao.GetAll();
                BizObject.CacheData(key, obj);
            }
            return obj;
        }
        /// <summary>
        /// Search MatHang object in table MatHang.
        /// </summary>
        /// <param name="t">Condition for Search.</param>

        /// <returns>List MatHangResult objects.</returns>

        public static List<MatHangResult> SearchMatHangSomeCondition(MatHang t)
        {
            return MatHangDao.SearchMatHangSomeCondition(t);
        }
        public static List<MatHangResult> SearchMatHangFormListMH(MatHang t)
        {
            return MatHangDao.SearchMatHangFormListMH(t);
        }
        public static bool Publish(MatHang obj)
        {
            return MatHangDao.Publish(obj);
        }
        /// <summary>
        /// Get a MatHang data object by primary key. 
        /// </summary>
        /// <param name="maMatHang" >This is primary key.</param>
        /// <returns>A MatHang object.</returns>

        public static MatHang Get(string maMatHang)
        {
            MatHang obj = null;
            string key = "MatHang_Get_" + string.Format("{0}", maMatHang);
            if (BizObject.Cache[key] != null)
            {
                obj = (MatHang)BizObject.Cache[key];
            }
            else
            {
                obj = MatHangDao.Get(maMatHang);
                BizObject.CacheData(key, obj);
            }
            return obj;
        }

        /// <summary>
        /// This function to Delete MatHang object by primary key.
        /// </summary>
        /// <param name="maMatHang" >This is primary key.</param>
        /// <returns>If succesful return True else  return False.</returns>

        public static bool Delete(string maMatHang)
        {
            BizObject.PurgeCacheItems("MatHang");

            return MatHangDao.Delete(maMatHang);
        }
        public static int GenerateKey()
        {
            return MatHangDao.GenerateKey();
        }
        public static List<MatHangResult> GetMatHangByLoaiMatHang(int maLoaiMatHang)
        {
            return MatHangDao.GetMatHangByLoaiMatHang(maLoaiMatHang);
        }
        public static MatHang GetMatHangByIDInPhieuNhaphang(string maMatHang)
        {
            return MatHangDao.GetMatHangByIDInPhieuNhaphang(maMatHang);
        }
        public static int GetSoLuongTonByDonViTinh(string maMatHang, int maKho, int maDonViTinh)
        {
            if (maMatHang == string.Empty  || maDonViTinh < 1)
                return 0;
            return MatHangDao.GetSoLuongTonByDonViTinh(maMatHang, maKho, maDonViTinh);
        }
        public static List<MatHangResult> GetMatHangByChungXe(int chungXe)
        {
            return MatHangDao.GetMatHangByChungXe(chungXe);
        }
        public static MatHang GetMatHangByMaPhuTungInPhieuNhaphang(string maPT)
        {
            return MatHangDao.GetMatHangByMaPhuTungInPhieuNhaphang(maPT);
        }
    }
}